<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>

<meta http-equiv="X-UA-Compatible" content="edge" />
<c:if test="${fn:contains(sessionInfo.resourceList, '/registerMedicine/detail')}">
	<script type="text/javascript">
		$.canDetail = true;
	</script>
</c:if>
<title>开药</title>
	<script type="text/javascript">
	var dataGrid;
	var errorCode = '${errorCode}';	
	var timeSegmentStr = '${msg}';
	
	$(function() {
		if(errorCode == '0') {
			dataGrid = $('#dataGrid').datagrid({
				url : '${ctx}' + '/chargeXRay/patientGrid?timeSegmentStr=' + timeSegmentStr,
				striped : true,
				rownumbers : true,
				pagination : true,
				singleSelect : true,
				idField : 'id',
				sortName : 'id',
				sortOrder : 'asc',
				pageSize : 50,
				pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
				frozenColumns : [ [ {
					width : '30',
					title : 'id',
					field : 'id',
					sortable : true
				}, {
					width : '130',
					title : '病人',
					field : 'patientName',
					sortable : true
				} ,{
					width : '80',
					title : '挂号方式',
					field : 'type',
					sortable : true,
					formatter : function(value, row, index) {
						switch (value) {
						case 0:
							return '预约挂号';
						case 1:
							return '现场挂号';
						}
					}
				} ,{
					width : '130',
					title : '预约挂号时间',
					field : 'reserveTime'
				} ,{
					width : '130',
					title : '现场取号时间',
					field : 'registerTime'
				} ,{
					width : '50',
					title : '排序号',
					field : 'seq'
				} ,{
					field : 'action',
					title : '操作',
					width : 200,
					formatter : function(value, row, index) {
						var str = '&nbsp;';
						if(row.seq != null) {
							if ($.canDetail) {
								str += $.formatString('<a href="javascript:void(0)" onclick="detail(\'{0}\');" >开药详情</a>', row.id);
								str += '&nbsp;||&nbsp;';
								str += $.formatString('<a href="javascript:void(0)" onclick="deletePrescription(\'{0}\');" >重新开药</a>', row.id);
								str += '&nbsp;||&nbsp;';
							}
							str += $.formatString('<a href="javascript:void(0)" onclick="history(\'{0}\');" >开药历史</a>', row.patientId);
						}
						return str;
					}
				} ] ],
				toolbar : '#toolbar'
			});
		}
		
	});
	
	function history(patientId) {
		parent.$.modalDialog({
			title : '开药历史',
			width : 1200,
			height : 400,
			href : '${ctx}/registerMedicine/historyPage?patientId=' + patientId
		});
	}
	
	function detail(id) {
		debugger;
		parent.$.modalDialog({
			title : '开药详情',
			width : 1000,
			height : 400,
			href : '${ctx}/registerMedicine/detailPage?registerId=' + id
		});
	}
	
	function deletePrescription(id) {
		$.ajax({
			type: "POST",
			async: false,
			data:  {
				'registerId':id
			},
	        url: '${ctx}/registerMedicine/deletePrescription',
	        dataType: "json",
	        success:function(result) {
	        	if(result.status.errorCode == 0) {
	        		$.messager.alert('成功', result.status.errorMsg, 'info');
	        	} else {
	        		$.messager.alert('错误', result.status.errorMsg, 'error');
	        	}
	        },
	        error:function(result) {
	        }
   	 	});
	}
	
	</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',fit:true,border:false" title="${msg }">
		<table id="dataGrid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>